#include <iostream>
#include <queue>
#include <algorithm>

#include "common/utils.hpp"

/*
上个节点能否作为参数传入递归函数中？？？
答：不可以，递归的函数在入栈时pre是一个16进制的地址，这个值在入栈时就确定了
*/
TreeNode* pre;

void traversal(TreeNode* root, int& ret) {
    if (root == nullptr) return;

    traversal(root->left, ret);

    if (pre != nullptr) {
        ret = std::min(ret, root->val - pre->val);
    }
    pre = root;

    traversal(root->right, ret);
}

/*
二叉搜索树的中序遍历结果是严格有序的序列
*/
int getMinimumDifference(TreeNode* root) {
    int ret = INT_MAX;
    traversal(root, ret);

    return ret;
}

extern TreeNode* commonRoot;

int main() {
    std::vector<int> nums = {236,104,701,-1,227,-1,911};
    TreeNode* node = createTreeNodeByArray(nums);
    printTreeNode(node);
    std::cout << "=================\n";
    int ret = getMinimumDifference(node);
    std::cout << "ret: " << ret;
}